﻿@namespace ThingsGateway.Demo
@using BlazorComponent;
@using Microsoft.AspNetCore.Components.Web;
@using System.Reflection;

@using ThingsGateway.Foundation.OpcDa;
@using ThingsGateway.Foundation.OpcDa.Rcw;
@using Masa.Blazor
@inherits BasePopupComponentBase

<PModal Persistent Title=@Plc?.OpcDaConfig?.ToString() Value="Visible" Width=1200 ValueChanged=@((a=>{if(!a)
        ClosePopupAsync();})) OnSave="()=>{}" SaveText="关闭">

     <SaveContent Context="save">
@{
#if Plugin
         <MMenu OffsetY Context="menu">
             <ActivatorContent>
                 <MButton @attributes="@menu.Attrs" Color="primary" Class="my-1  mx-2 " Disabled="isDownLoading" Loading="isDownLoading">
                     导出
                     <AppChevronDown></AppChevronDown>
                 </MButton>
             </ActivatorContent>
             <ChildContent>
                 <MList>
                     <MListItem Color="primary" OnClick="DownDeviceExport" Disabled="isDownLoading" >  导出到excel </MListItem>
                     <MListItem Color="primary" OnClick="DeviceImport" Disabled="isDownLoading" >导入到系统</MListItem>
                 </MList>

             </ChildContent>
         </MMenu>
#endif
}
     </SaveContent>

 <ChildContent>
         @if (Visible)
        {

            <MRow Class="pa-4"
                  Justify="JustifyTypes.SpaceBetween">
                <MCol Cols="12" Md="6">
                    <MTreeview @bind-Value=Selected @bind-Active=Actived SelectionType="SelectionType.Leaf"
                               Items=Nodes TItem=OpcDaTagModel
                               Color="warning"
                                  Selectable
                                  Activatable
                                  OpenOnClick
                                LoadChildren=PopulateBranchAsync
                                TKey=BrowseElement ItemKey="r=>r.Tag"
                                Style="height:500px;overflow-y:auto;"
                                ItemText="r=>r.Name"
                                ItemChildren="r=>r.Nodes">
                     </MTreeview>
                 </MCol>
                 <MCol Cols="12" Md="6">
                     <MCardText Style="height:500px;overflow-y:auto;">
                         @if (Actived?.Count == 0)
                        {
                            <div key="title"
                                 class="text-h6 font-weight-light grey--text pa-4 text-center">
                                选择左侧节点
                            </div>
                        }
                        else
                        {
                            <ScrollXTransition>
                                <MSheet Outlined Class="ma-0 pa-1">
                                     <MRow Align="AlignTypes.Center">
                                         <MCol>
                                             <MListItem>
                                                 <ItemContent>
                                                     <MListItemContent>
                                                         <MListItemTitle>NodeId </MListItemTitle>
                                                     </MListItemContent>
                                                 </ItemContent>
                                             </MListItem>
                                         </MCol>
                                         <MDivider Vertical
                                                    Center />
                                         <MCol>
                                             <MLabel Class=@($"ma-1")> @Actived.FirstOrDefault().ItemName  </MLabel>
                                        </MCol>

                                    </MRow>
                                </MSheet>
                                @if (nodeAttributes != null)
                                {
                                    @foreach (var item in nodeAttributes)
                                    {
                                        <MSheet Outlined Class="ma-0 pa-1">
                                             <MRow Align="AlignTypes.Center">
                                                 <MCol>
                                                     <MListItem>
                                                         <ItemContent>
                                                             <MListItemContent>
                                                                 <MListItemTitle>@item.Description </MListItemTitle>
                                                                </MListItemContent>
                                                            </ItemContent>
                                                        </MListItem>
                                                    </MCol>
                                                    <MDivider Vertical
                                                            Center />
                                                 <MCol>
                                                     <MLabel Class=@($"{(item.ResultID.Failed()?"red--text":"green--text")} ma-1")> @item.Value  </MLabel>
                                                </MCol>

                                            </MRow>
                                        </MSheet>
                                    }

                                }


                            </ScrollXTransition>

                        }
                    </MCardText>
                </MCol>

                <MDivider Vertical></MDivider>

             </MRow>

            <MOverlay Absolute Value="overlay" Opacity="0.8">
                 <span class="green--text text--darken-2">
                     @("正在获取OpcDa节点...")
                 </span>
                 <MProgressCircular Indeterminate Width=6 Size="30"></MProgressCircular>
             </MOverlay>
        }
 </ChildContent>
</PModal>
